package com.time.hellotime.app;

import android.content.Context;
import android.content.SharedPreferences;

import com.time.hellotime.utils.FileUtils;

import java.io.File;
import java.util.Set;

/**
 * 基本配置信息
 * Created by Bing on 2016/8/23.
 * E-mail is tx16bing@163.com
 */
public class AppConfig {
    private volatile static AppConfig appConfig;

    // App SharePreference
    private SharedPreferences preferences;

    // App 根目录
    public String APP_PATH_ROOT;

    private AppConfig() {
        preferences = MyApplication.getInstance().getSharedPreferences("Time_person_pre", Context.MODE_PRIVATE);
    }

    public static AppConfig getInstance(){
        if (appConfig == null){
            synchronized (AppConfig.class){
                if (appConfig == null){
                    appConfig = new AppConfig();
                }
            }
        }
        return appConfig;
    }

    public void initDir(){
        // 创建根目录
        APP_PATH_ROOT = FileUtils.getRootPath().getAbsolutePath() + File.separator + "Time_person";
        FileUtils.initDirectory(APP_PATH_ROOT);
    }

    public SharedPreferences getPreferences() {
        return preferences;
    }

    public void putInt(String key, int value) {
        preferences.edit().putInt(key, value).commit();
    }

    public int getInt(String key, int defValue) {
        return preferences.getInt(key, defValue);
    }

    public void putString(String key, String value) {
        preferences.edit().putString(key, value).commit();
    }

    public String getString(String key, String defValue) {
        return preferences.getString(key, defValue);
    }

    public void putBoolean(String key, boolean value) {
        preferences.edit().putBoolean(key, value).commit();
    }

    public boolean getBoolean(String key, boolean defValue) {
        return preferences.getBoolean(key, defValue);
    }

    public void putLong(String key, long value) {
        preferences.edit().putLong(key, value).commit();
    }

    public long getLong(String key, long defValue) {
        return preferences.getLong(key, defValue);
    }

    public void putFloat(String key, float value) {
        preferences.edit().putFloat(key, value).commit();
    }

    public float getFloat(String key, float defValue) {
        return preferences.getFloat(key, defValue);
    }

    public void putStringSet(String key, Set<String> value) {
        preferences.edit().putStringSet(key, value).commit();
    }

    public Set<String> getStringSet(String key, Set<String> defValue) {
        return preferences.getStringSet(key, defValue);
    }

}
